<template>
  <div>
    <div class="xinwenguanlis">
      <!-- 置顶的 -->
      <!-- 头 -->
      <div class="xinwenzhiding" v-show="showtou">
        <div @click="xadds">
          <span>新增新闻</span>
        </div>
        <div>
          <span>发布时间</span>
          <el-date-picker
            v-model="dStartTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="开始日期"
          ></el-date-picker>-
          <el-date-picker
            v-model="dEndTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="结束日期"
          ></el-date-picker>
        </div>
        <div>
          <span>公文等级</span>
          <el-select v-model="nGid">
            <el-option label="特急" value="1"></el-option>
            <el-option label="加急" value="2"></el-option>
            <el-option label="平急" value="3"></el-option>
          </el-select>
        </div>
        <div>
          <span>新闻类别</span>
          <el-select v-model="nTid">
            <el-option
              v-for="item in AllnewstypesEmpty"
              :key="item.nTid"
              :label="item.nNewsType"
              :value="item.nTid"
            ></el-option>
          </el-select>
        </div>
        <div>
          <input
            @blur="getData"
            class="danweimingc"
            type="text"
            v-model="sContent"
            placeholder="标题/内容摘要"
          />
          <el-button type="primary" @click="GetAllnews">查询</el-button>
        </div>
      </div>
      <!-- 内容 -->
      <div class="navs" v-show="showneirong">
        <thead></thead>

        <el-table
          :data="Allnews.slice((currentPage-1)*pageSize,currentPage*pageSize)"
          tooltip-effect="dark"
          style="width: 100%"
          @select="tabid(nUid)"
          @selection-change="handleSelectionChange"
        >
          <el-table-column prop="sTitle" label="标题" width="140px" align="center"></el-table-column>
          <el-table-column label width="50px" align="center">
            <template slot-scope="scope">
              <span v-if="(scope.row.nTop == 1)">置顶</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="nNewsType"
            label="新闻类别"
            width="140px"
            show-overflow-tooltip
            align="center"
          ></el-table-column>
          <el-table-column prop="sContent" label="文章内容" show-overflow-tooltip align="center"></el-table-column>
          <el-table-column
            prop="sGrade"
            label="公文等级"
            width="169px"
            show-overflow-tooltip
            align="center"
          ></el-table-column>
          <el-table-column
            prop="sCuName"
            label="编写人"
            width="140px"
            show-overflow-tooltip
            align="center"
          ></el-table-column>
          <el-table-column
            prop="sSuName"
            label="审核人"
            width="140px"
            show-overflow-tooltip
            align="center"
          ></el-table-column>
          <el-table-column prop="dSendTime" label="发布日期" show-overflow-tooltip align="center"></el-table-column>
          <el-table-column prop="sContentType" label="附件" show-overflow-tooltip align="center"></el-table-column>
          <el-table-column width="169px" label="操作" show-overflow-tooltip align="center">
            <template slot-scope="scope">
              <button v-if="scope.row.nTop==0" @click="changeTop1(scope.row)">置顶</button>
              <button v-if="scope.row.nTop==1" @click="changeTop0(scope.row)">取消置顶</button>
              |
              <button @click="set(scope.row)">编辑</button>
              |
              <button href="#" @click.prevent="dialogVisible = true">删除</button>
               <el-dialog title="提示" :visible.sync="dialogVisible" width="30%">
          <p>此操作将永久删除该文件, 是否继续?</p>
          <span slot="footer" class="dialog-footer">
            <button class="button1" @click="dialogVisible = false">取 消</button>
            <button class="button2" type="primary" @click="delnews(scope.row)">确 定</button>
          </span>
        </el-dialog>
            </template>
          </el-table-column>
        </el-table>
        <div>
          <!-- 分页 -->
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page.sync="currentPage"
            :page-size="pageSize"
            background
            layout="total, prev, pager, next"
            :total="Allnews.length"
          ></el-pagination>
        </div>
      </div>

      <!-- 预览 -->
      <div class="yulan_left" v-show="yulanshow">
        <div class="biaoti">{{formLabelAlign.name}}</div>
        <div class="xinxi">
          <div class="ly">
            来源:
            <span>{{formLabelAlign.newsly}}</span>
          </div>
          <div class="fbsj">
            发布时间:
            <span>{{date}}</span>
          </div>
          <div class="fbr">
            发布人:
            <span>{{formLabelAlign.region6}}</span>
          </div>
          <div class="shr">
            审核人:
            <span>{{formLabelAlign.region4}}</span>
          </div>
          <div class="lll">
            浏览量:
            <span>999+</span>
          </div>
          <div class="tb">
            <svg
              t="1627982764717"
              class="icon"
              viewBox="0 0 1024 1024"
              version="1.1"
              xmlns="http://www.w3.org/2000/svg"
              p-id="2318"
              width="20"
              height="20"
            >
              <path
                d="M691.73 389.353h56.757v56.757H691.73zM355.919 218.757h312.162v75.675h56.757V162H299.162v132.432h56.757zM384.297 710.649h255.405v56.757H384.297zM384.297 616.054h255.405v56.757H384.297z"
                p-id="2319"
                fill="#1296db"
              />
              <path
                d="M180.919 294.758V616.38h101.442V862H745.873V616.38H843.08V294.758H180.919z m508.199 510.485h-350V549.838h350v255.405z m97.206-245.62h-40.45v-66.542H282.362v66.542h-44.685V351.515h548.649v208.108z"
                p-id="2320"
                fill="#1296db"
              />
            </svg>
          </div>
          <div class="dy">打印</div>
        </div>

        <!-- 新闻 -->
        <div class="yulan-xinwen">{{formLabelAlign.newsnr}}</div>
        <!-- 附件 -->
        <div class="fujian_yulan">附件1： {{formLabelAlign.sContentType}}</div>
        <div class="fanhui_yulan" @click="fanhui_yulan">
          <button>返回</button>
        </div>
      </div>
      <div class="mod4 flex-col" v-show="showxinzeng">
        <!-- 头部 -->
        <div class="first">
          <el-button
            type="info"
            @click="wenzhangxw"
            :class="operateValue ==='wz' ? 'anniu1' : 'anniu2' "
          >文章新闻</el-button>
          <el-button
            type="info"
            @click="shipin"
            :class="operateValue ==='sp' ? 'anniu1' : 'anniu2' "
          >视频新闻</el-button>
        </div>
        <!-- /头部 -->

        <!-- 身体 -->
        <div class="container">
          <div class="container_left">
            <el-form :label-position="labelPosition" label-width="140px">
              <el-form-item label="文章标题">
                <el-input v-model="formLabelAlign.name"></el-input>
                <el-checkbox class="zd" v-model="checked">置顶</el-checkbox>
              </el-form-item>
              <el-form-item label="显示区域" class="xianshi">
                <el-select v-model="formLabelAlign.region1" placeholder="请选择显示区域">
                  <el-option label="仅在新闻类别显示" :value="1"></el-option>
                  <el-option label="仅在公安头条显示" :value="2"></el-option>
                  <el-option label="新闻类别和轮播图都显示" :value="3"></el-option>
                  <el-option label="仅在轮播图显示" :value="4"></el-option>
                </el-select>
                <!-- <template>
                   <select class="ysselect" v-model="formLabelAlign.region1" placeholder="请选择显示区域">
                      <option selected value="">请选择显示区域</option>
                <option value="1">仅在新闻类别</option>
                <option value="2">仅在轮播图显示</option>
                <option value="3">仅在公安头条</option>
                 <option value="4">新闻类别和轮播图显示</option>
                </select></template>-->
              </el-form-item>
              <!-- 选择新闻类别显示内容 -->
              <div
                v-if="formLabelAlign.region1=='3'||formLabelAlign.region1=='4'"
                class="lunbo-xianshi"
              >
                <el-form-item label="封面图">
                  <el-upload
                    action
                    class="upload-demo"
                    ref="upload"
                    name="file"
                    :show-file-list="false"
                    :auto-upload="true"
                    :http-request="uploadFile"
                  >
                    <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                  </el-upload>
                </el-form-item>
                <div class="tishi" v-show="formLabelAlign.region1=='4'==false">
                  <!-- 轮播图: 建议尺寸：
                  <span>305*210</span>，支持png、jpg、jpeg格式-->
                </div>
              </div>
              <!-- 公安头条显示内容 -->
              <el-form-item class="leibie" label="新闻类别">
                <el-select v-model="formLabelAlign.region2" placeholder="请选择新闻类别">
                  <el-option
                    v-for="item in AllnewstypesEmpty"
                    :key="item.nTid"
                    :label="item.nNewsType"
                    :value="item.nTid"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="公文等级" class="gongwen">
                <el-select v-model="formLabelAlign.region3" placeholder="请选择公文等级">
                  <el-option label="特急" :value="1"></el-option>
                  <el-option label="加急" :value="2"></el-option>
                  <el-option label="平急" :value="3"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="审核人">
                <el-select
                  class="shenheren"
                  @change="AlluserBynOid"
                  v-model="formLabelAlign.region4"
                  placeholder="请选择单位"
                >
                  <el-option
                    v-for="item in Allorganizations"
                    :key="item.nUid"
                    :label="item.sName"
                    :value="item.nOid"
                  ></el-option>
                </el-select>
                <el-select
                  class="renyuan1"
                  v-model="formLabelAlign.region5"
                  @change="nuidnews"
                  placeholder="请选择人员"
                >
                  <el-option
                    v-for="item in newsAlluserBynOid"
                    :key="item.nUid"
                    :label="item.sName"
                    :value="item.nUid"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="编写人">
                <el-select class="bianxieren" v-model="formLabelAlign.region6" placeholder="请选择编写人">
                  <el-option :label="newsname" :value="nOids"></el-option>
                </el-select>
                <el-select class="renyuan2" v-model="formLabelAlign.region7" placeholder="请选择人员">
                  <el-option :label="newsname" :value="nUids"></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="来源">
                <el-input v-model="formLabelAlign.sSource"></el-input>
              </el-form-item>
              <el-form-item label="审核">
                <el-checkbox v-model="checked1">审核通过</el-checkbox>
                <el-checkbox v-model="checked2">审核未通过</el-checkbox>
              </el-form-item>
              <el-form-item label="附件" v-show="isFujian">
                <el-upload
                  action
                  class="upload-demo"
                  ref="upload"
                  name="file"
                  :show-file-list="false"
                  :auto-upload="true"
                  :http-request="uploadFile2"
                >
                  <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                </el-upload>
              </el-form-item>
              <el-form-item label="上传视频" v-show="isShipin">
                <el-upload
                  action
                  class="upload-demo"
                  ref="upload"
                  name="file"
                  :show-file-list="false"
                  :auto-upload="true"
                  :http-request="uploadFile3"
                >
                  <el-button slot="trigger" size="small" type="primary">选取文件</el-button>
                </el-upload>
              </el-form-item>
              <el-form-item label="文章内容" prop="desc" class="hdxs1">
                <textarea v-model="formLabelAlign.newsnr" name id cols="30" rows="10" class="hdxs"></textarea>
              </el-form-item>
            </el-form>
            <div class="footer">
              <el-button @click="Addnews" v-show="addshow" type="primary" class="fabu">发布</el-button>
              <el-button @click="upDatenews" v-show="updateshow" type="primary" class="fabu">修改</el-button>
              <el-button type="info" @click="yulanClick" plain class="yulan">预览</el-button>
              <el-button type="info" plain class="fanhui" @click="fanhuiss">返回</el-button>
            </div>
          </div>
          <div class="container_right">
            <!-- 上 -->
            <div class="container_right_top">
              <span class="cover">接收单位</span>
            </div>
            <!-- /上 -->
            <!-- 中 -->
            <div class="container_right_body">
              <div class="box">
                <el-table
                  ref="multipleTable"
                  :data="Allorganizations"
                  tooltip-effect="dark"
                  @select="newsid"
                  style="width: 100%"
                  @selection-change="handleSelectionChange"
                >
                  <el-table-column type="selection" width="55"></el-table-column>
                  <el-table-column prop="sName" label="全选" width="120">
                    <template slot-scope="scope">{{ scope.row.sName }}</template>
                  </el-table-column>
                </el-table>
              </div>
            </div>
            <!-- /中 -->
            <!-- 下 -->
            <!-- /下 -->
          </div>
        </div>
        <!-- /身体 -->
      </div>
    </div>
  </div>
</template>

<script>
import Cookies from 'js-cookie'
export default {
  data () {
    return {
      dialogVisible:false,
      checkhuixian: [],
      PostSelectNewsEmpty: [],
      AllnewstypesEmpty: [],
      date: new Date(),
      // 日期
      dStartTime: '',
      dEndTime: '',
      nTid: '',
      nGid: '',
      sContent: '',
      ids: 0,
      isShipin: false,
      isFujian: true,
      operateValue: 'wz',
      fileList: [{ name: 'food.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' }, { name: 'food2.jpeg', url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100' }],

      // 获取单位的数据
      Allorganizations: [],
      // 所有新闻
      Allnews: [],
      // 表格
      xinwenleibie: '',
      pid: '',
      list: [
      ],
      // 每页数据条数
      pageSize: 10,
      currentPage: 1,
      total: 20,
      biaoti: '',
      xinwen: '',
      wenzhang: '',
      dengji: '',
      bianxi: '',
      shenhe: '',
      riqi: '',
      fujian: '',
      newlist: [{
        biaoti: '',
        xinwen: '',
        wenzhang: '',
        dengji: '',
        bianxi: '',
        shenhe: '',
        riqi: '',
        fujian: '',
        value: '',
      }],
      selected: [
        { id: 1, name: '平级' },
        { id: 2, name: '高级' },
      ],
      keywords: '',
      // 分页
      handleSizeChange (val) {
        console.log(`每页 ${val} 条`);
        this.currentPage = 1;
        // this.pageSize = val;
      },
      handleCurrentChange (val) {
        console.log(`当前页: ${val}`);
        // this.currentPage = val;
      },
      // 日期


      // 上传照片
      dialogImageUrl: '',
      dialogVisible: false,
      fileList: [],
      constants: {},
      labelPosition: 'right',
      formLabelAlign: {
        newsly: '',
        sSource:'',
        newsnr: '',
        name: '',
        region1: null,
        region2: null,
        region3: null,
        region4: null,
        region5: null,
        region6: null,
        region7: null,
        type: '',
        fujianname: ''
      },
      checked: false,
      region1: '',
      region2: '',
      region3: '',
      region4: '',
      region5: '',
      region6: '',
      region7: '',
      yulanshow: false,
      checked1: true,
      checked2: false,
      showxinzeng: false,
      showneirong: true,
      showtou: true,
      addshow: false,
      updateshow: false,
      desc: '',
      // 用户id
      nUids: [],
      // 单位id
      nOids: [],
      // 登录人
      newsname: [],
      // 单位对应的人
      newsdwID: [],
      // 单位id 拼接
      nOidList: [],
      // 新增新闻成功时的主键id
      keysid: 0,
      // 新闻对应的唯一id
      newID: '',
      // 回显表格多选框
      checkhuixian: [],
      newsAlluserBynOid: [],
      Allorganizations: [],
      pickerOptions: {
        disabledDate (time) {
          return time.getTime() > Date.now();
        },
      },
      PostAddpictureEmpty: [],
      PostAddpictureEmpty2: [],
      PostAddpictureEmpty3: [],
      sPicUrl: '',
      postUrl: '',
      postUrl2: '',
      postUrl3: '',
      nNid: 1,
      sContentType: '',
      sContent: '',
      //附件参数
      nNid: 1,
      sContentType: '',
      sContent: '',
      resId: '',
    };
  },
  created () {
    this.GetAllnews();
    this.GetAllorganizations();
    this.Allnewstypes();
    // this.Addcontens()

  },
  mounted () {
    let _this = this; // 声明一个变量指向Vue实例this，保证作用域一致
    this.timer = setInterval(() => {
      _this.date = this.getTime(); // 修改数据date
    }, 1000)
  },
  beforeDestroy () {
    if (this.timer) {
      clearInterval(this.timer); // 在Vue实例销毁前，清除我们的定时器
    }
  },
  methods: {
    // 新增图片和附件和视频至服务器
    async Addnews () {
      if (this.postUrl != null && this.postUrl != '') {
        this.Addpictures()
      }
      if (this.postUrl3 != null && this.postUrl3 != '') {
        this.video()
      }
      this.postAddnews()
      // this.Addcontens()
         this.$message({
            type: 'success',
            message: '发布成功!'
          });
    },
    //视频上传服务器
    async video () {
      const config = {
        headers: {
          "Content-Type": "multipart/form-data"
        },
      }
      let formDataImg = new FormData()
      formDataImg.append('sPicUrl', this.postUrl3.name)
      formDataImg.append('file', this.postUrl3)
      const { data: res } = await this.$http.post('/api/SingleImageUpload/Post', formDataImg, config)
      console.log(res, 'img')
      this.PostAddpictureEmpty3 = res
      this.Addpicture()
      this.GetAllnews()
      // this.$router.go(0)
    },
    //上传视频
    uploadFile3 (param) {
      console.log(param.file);
      this.postUrl3 = param.file;
      console.log(param.file.name);
      let uploadData = new FormData();
      uploadData.append('file', param.file);
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
    },

    //上传图片
    uploadFile (param) {
      console.log(param.file);
      this.postUrl = param.file;
      console.log(param.file.name);
      let uploadData = new FormData();
      uploadData.append('file', param.file);
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
    },

    //附件上传服务器
    async Addcontens () {
      const config = {
        headers: {
          "Content-Type": "multipart/form-data"
        },
      }
      let formDataImg = new FormData()
      formDataImg.append('sPicUrl', this.postUrl2.name)
      formDataImg.append('file', this.postUrl2)
      const { data: res } = await this.$http.post('/api/SingleImageUpload/Post', formDataImg, config)
      console.log(res, 'img')
      this.PostAddpictureEmpty2 = res
      this.Addpicture2()
      this.GetAllnews()
      // this.$router.go(0)
    },
    async Addpictures () {
      const config = {
        headers: {
          "Content-Type": "multipart/form-data"
        },
      }
      let formDataImg = new FormData()
      formDataImg.append('sPicUrl', this.postUrl.name)
      formDataImg.append('file', this.postUrl)
      const { data: res } = await this.$http.post('/api/SingleImageUpload/Post', formDataImg, config)
      console.log(res, 'img')
      this.PostAddpictureEmpty = res
      this.Addpicture()
    },
    //新增附件接口
    async Addpicture2 () {
      let formData = new FormData()
      formData.append('nNid', this.keysid)
      formData.append('sContentType', this.postUrl2.name)
      formData.append('sContent', this.PostAddpictureEmpty2)
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      const { data: res } = await this.$http.post('/api/newscontent/Post_Addnewscontent', formData, config)
      console.log(res);

      this.keysid = ''
    },
    uploadFile2 (param) {
      console.log(param.file);
      this.postUrl2 = param.file;
      console.log(param.file.name);
      let uploadData = new FormData();
      uploadData.append('file', param.file);
      let config = {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }
    },
    //新增图片接口
    async Addpicture () {
      let formData = new FormData()
      formData.append('nTid', 1)
      formData.append('sPicUrl', this.PostAddpictureEmpty)
      // formData.append('sPicture', this.sPicture)
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      const { data: res } = await this.$http.post('/api/picture/Post_Addpicture', formData, config)
      console.log(res);
      this.resId = res
      this.PostAddpictureEmpty = ''
      //this.postAddnews()
    },
    // 图片上传成功的回调
    changeFile (file, fileList) {
      this.fileUpload = file
    },
    getTime () {
      var date1 = new Date();
      var year = date1.getFullYear();
      var month = date1.getMonth() + 1;
      var day = date1.getDate();
      var hours = date1.getHours();
      var minutes = date1.getMinutes();
      var seconds = date1.getSeconds();
      return (
        year +
        "/" +
        month +
        "/" +
        day +
        " " +
        hours +
        ":" +
        minutes +
        ":" +
        seconds
      );
    },
    // 获取单位对应的人员
    async AlluserBynOid (id) {
      console.log(id);
      const { data: res } = await this.$http.get('/api/user/Get_AlluserBynOid', {
        params: {
          innOid: id
        }
      })
      console.log(res);
      this.newsAlluserBynOid = res
    },
 
    // 获取所有新闻
    async GetAllnews () {
      this.newsname = Cookies.get('username')
      this.nUids = Cookies.get('nUid')
      this.nOids = Cookies.get('nOid')
      let formData = new FormData()
      formData.append("dStartTime", this.dStartTime);
      formData.append("dEndTime", this.dEndTime);
      formData.append("nGid", this.nGid);
      formData.append("nTid", this.nTid);
      formData.append("sContent", this.sContent);

      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      const { data: res } = await this.$http.post('/api/news/Post_Allnews', formData, config)
      res.sort(this.topSort);
      console.log(res, '111');
      this.Allnews = res;
      this.dStartTime = ''
      this.dEndTime = ''
      this.nGid = ''
      this.nTid = ''
      this.sContent = ''
    },


    // 接口 获取所有单位
    async GetAllorganizations () {
      const { data: res } = await this.$http.get('/api/organization/Get_Allorganizations')
      this.Allorganizations = res
    },
    //获取所有新闻类别内容
    async Allnewstypes () {
      const { data: res } = await this.$http.get(
        "/api/newstype/Get_Allnewstypes", {
        params: {
          nState: 1
        }
      }
      );
      this.AllnewstypesEmpty = res;
      console.log(res);
    },
    // 新增新闻
    async postAddnews () {
      let a, b;
      //  a是否置顶
      if (this.checked == true) {
        a = 1
      } else {
        a = 0
      }
      if (this.checked1 == true) {
        b = 1
      }
      if (this.checked2 == true && this.checked1 == false) {
        b = 0
      }
      // 获取当前时间 datetime
      let d = new Date();
      let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
      let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
      let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
      let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
      let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
      let timedate = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
      console.log(timedate);

      let formData = new FormData()
      // 标题
      formData.append('sTitle', this.formLabelAlign.name)
      // 审核人id
      formData.append('nSuid', this.ids)
      // 编写人id
      formData.append('nBuid', this.nUids)
      // 是否审核    1已审核；0未审核
      formData.append('nExamine', b)
      // 内容
      formData.append('sContent', this.formLabelAlign.newsnr)
      // 发布时间
      formData.append('dSendTime', timedate)
      // 浏览量
      formData.append('nNum', 999)
      // 是否置顶     1已置顶；0未置顶
      formData.append('nTop', a)
      // 来源
      formData.append('sSource', this.formLabelAlign.sSource)
      // 插图编号
      formData.append('nPictureNum', 4)
      // 等级编号
      formData.append('nGid', this.formLabelAlign.region3)
      // 类型编号
      formData.append('nTid', this.formLabelAlign.region2)
      // 区域编号
      formData.append('nDid', this.formLabelAlign.region1)
      // 附件类型
      formData.append('insContentType', this.formLabelAlign.fujianname)
      // 附件内容
      formData.append('insConUrl', '附件内容')

      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      // this.NewsAddnewscontent()
      // 添加新闻
      const { data: res } = await this.$http.post('/api/news/Post_Addnews', formData, config)
      console.log(res);
      this.keysid = res
      let adnew = {
        sTitle: this.formLabelAlign.name,
        nSuid: this.ids,
        nBuid: this.formLabelAlign.region6,
        nExamine: b,
        sContent: this.formLabelAlign.newsnr,
        dSendTime: timedate,
        nNum: 999,
        nTop: a,
        nPictureNum:'',
        nGid: this.formLabelAlign.region3,
        nTid: this.formLabelAlign.region2,
        nDid: this.formLabelAlign.region1,
        insContentType: this.formLabelAlign.fujianname,
        insConUrl: '附件内容'
      }
      this.formLabelAlign = []
      this.Allnews.push(adnew)
      this.GetAllnews()
      this.showneirong = true
      this.showxinzeng = false
      this.showtou = true
      if (this.postUrl2 != null && this.postUrl2 != '') {
        this.Addcontens()
      }
      this.Addnewsreceiveorg()
      this.resId = ''
    },
    // 修改新闻
    async upDatenews () {
      let a, b;
      //  a是否置顶
      if (this.checked == true) {
        a = 1
      } else {
        a = 0
      }
      if (this.checked1 == true) {
        b = 1
      }
      if (this.checked2 == true && this.checked1 == false) {
        b = 0
      }
      // 编写人
      this.formLabelAlign.region7=this.nCuid
      // 获取当前时间 datetime
      let d = new Date();
      let month = (d.getMonth() + 1) < 10 ? '0' + (d.getMonth() + 1) : (d.getMonth() + 1);
      let day = d.getDate() < 10 ? '0' + d.getDate() : d.getDate();
      let hours = d.getHours() < 10 ? '0' + d.getHours() : d.getHours();
      let min = d.getMinutes() < 10 ? '0' + d.getMinutes() : d.getMinutes();
      let sec = d.getSeconds() < 10 ? '0' + d.getSeconds() : d.getSeconds();
      let timedate = d.getFullYear() + '-' + month + '-' + day + ' ' + hours + ':' + min + ':' + sec;
      console.log(timedate);
      
      let formData = new FormData()
      // 新闻编号
      formData.append('nNewId', this.newID)
      // 标题
      formData.append('sTitle', this.formLabelAlign.name)
      // 审核人id
      formData.append('nSuid', this.formLabelAlign.region5)
      // 编写人id
      formData.append('nBuid', this.formLabelAlign.region7)
      // 是否审核    1已审核；0未审核
      formData.append('nExamine', b)
      // 内容
      formData.append('sContent', this.formLabelAlign.newsnr)
      // 发布时间
      formData.append('dSendTime', timedate)
      // 浏览量
      formData.append('nNum', 999)
      // 是否置顶     1已置顶；0未置顶
      formData.append('nTop', a)
      // 插图编号
      formData.append('nPictureNum', 4)
      // 来源
      formData.append('sSource', this.formLabelAlign.sSource)
      // 等级编号
      formData.append('nGid', this.formLabelAlign.region3)
      // 类型编号
      formData.append('nTid', this.formLabelAlign.region2)
      // 区域编号
      formData.append('nDid', this.formLabelAlign.region1)
      // // 附件类型
      // formData.append('insContentType', this.formLabelAlign.fujianname)
      // // 附件内容
      // formData.append('insConUrl', '附件内容')

      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      // this.NewsAddnewscontent()
      // 添加新闻
      const { data: res } = await this.$http.post('/api/news/Post_Updatenews', formData, config)
      console.log(res);
      this.keysid = res
  
      this.GetAllnews()
      this.showneirong = true
      this.showxinzeng = false
      this.showtou = true
      this.formLabelAlign = []
      // this.Addnewsreceiveorg()
    
     this.$message({
            type: 'success',
            message: '修改成功!'
          });
    },

    // 改变置顶状态
    async changeTop1 (row) {
      this.nNewId = row.nNewId
      let formData = new FormData()
      formData.append('nNewId', this.nNewId)
      formData.append('nTop', 1)
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      const { data: res } = await this.$http.post('/api/news/Post_UpdatenewsTop', formData, config)
      console.log(res);
    },
    // 改变置顶状态
    async changeTop0 (row) {
      this.nNewId = row.nNewId
      let formData = new FormData()
      formData.append('nNewId', this.nNewId)
      formData.append('nTop', 0)
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      const { data: res } = await this.$http.post('/api/news/Post_UpdatenewsTop', formData, config)
      console.log(res);
    },
    // 获取单位id
    newsid (row) {
      // console.log(row);
      this.newsdwID = row
      for (let i = 0; i < this.newsdwID.length; i++) {
        this.nOidList.push(this.newsdwID[i].nOid)
      }
      // 数组去重
      [...new Set(this.nOidList)]
      console.log([...new Set(this.nOidList)].join('|'));
      this.checkhuixian = [...new Set(this.nOidList)]
    },
    async Addnewsreceiveorg () {
      let formData = new FormData()
      // 部门拼接id
      formData.append('sOidList', [...new Set(this.nOidList)].join('|'))
      // 所属新闻id
      formData.append('nNid', this.keysid)
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      // 添加新闻
      const { data: res } = await this.$http.post('/api/newsreceiveorg/Post_Addnewsreceiveorg', formData, config)
      console.log(res);
    },

    async delnews (row) {
      this.dialogVisible=false
      let formData = new FormData()
      formData.append('nNewId', row.nNewId)
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      }
      const { data: res } = await this.$http.post('/api/news/Post_Deletenews', formData, config)
      console.log(res);
      this.GetAllnews()
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
    },
    yulanClick () {
      this.yulanshow = true
      this.showxinzeng = false
    },
    fanhui_yulan () {
      this.yulanshow = false
      this.showxinzeng = true
    },
    wenzhangxw () {
      this.operateValue = 'wz'
      this.isFujian = true
      this.isShipin = false
    },
    shipin () {
      this.operateValue = 'sp'
      this.isShipin = true
      this.isFujian = false
    },


    search (keywords, pid, xinwenleibie) {
      let newList = this.list
      newList = newList.filter(item => {
        if (item.biaoti.includes(keywords)) {
          return item
        }
      })
      newList = newList.filter(item => {
        if (item.xinwen.includes('')) {
          return item
        }
      })
      return newList
    },
    // 改变置顶状态
    async changeTop1 (row) {
      this.nNewId = row.nNewId;
      let formData = new FormData();
      formData.append("nNewId", this.nNewId);
      formData.append("nTop", 1);
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
      };
      const { data: res } = await this.$http.post(
        "/api/news/Post_UpdatenewsTop",
        formData,
        config
      );
      console.log(res);
      this.GetAllnews();
    },
    // 改变置顶状态
    async changeTop0 (row) {
      this.nNewId = row.nNewId;
      let formData = new FormData();
      formData.append("nNewId", this.nNewId);
      formData.append("nTop", 0);
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded",
        },
      };
      const { data: res } = await this.$http.post(
        "/api/news/Post_UpdatenewsTop",
        formData,
        config
      );
      console.log(res);
      this.GetAllnews();
    },
    getData () {
      //   const obj = [{ gongwen: this.pid, xinw: this.xinwenleibie, search: this.keywords }]
      //   console.log(obj);
    },
    // 新增按钮
    xadds () {
      this.addshow = true
      this.showneirong = false
      this.showxinzeng = true
      this.showtou = false
    },
    // 编辑按钮
    async set (row) {
      this.updateshow = true
      this.showneirong = false
      this. addshow=false
      this.showxinzeng = true
      this.showtou = false
      this.newID = row.nNewId

      this.sTitle = row.sTitle
      this.nSuid = row.nSuid
      this.nBuid = row.nBuid
      // 是否审核
      // this.checked1 = row.nExamine
      // this.checked2 = row.nExamine
      // 是否置顶
      this.checked = row.nTop
      // this.nExamine = row.nExamine
      // 标题
      this.formLabelAlign.name = row.sTitle
      // 显示区域
      this.formLabelAlign.region1 = row.nAreaId
      // 新闻类别
      this.formLabelAlign.region2 = row.nTid
      // 公文等级
      this.formLabelAlign.region3 = row.nGid
      // 审核人单位
      this.formLabelAlign.region4 = row.nSoid
      // 审核人
      this.formLabelAlign.region5 = row.nSuid
      // 编写人单位名称
      this.formLabelAlign.region6 = row.sCoName
      // 编写人名称
      this.formLabelAlign.region7 = row.sCuName
      // 来源
      this.formLabelAlign.sSource = row.sSource
      // // 内容
      this.formLabelAlign.newsnr = row.sContent
      // 编写人id
      this.nCuid=row.nCuid
    // 附件类型
      this.formLabelAlign.sContentType=row.sContentType
        // 表格回显
      console.log(this.checkhuixian);

      // // 等级编号
      // this.formLabelAlign.region3 = row.nGid
      // // 类型编号
      // this.formLabelAlign.region2 = row.nTid
      // this.formLabelAlign.fujianname = row.nDid
      this.getnUid()
      this.getcnUid ()
      const { data: res } = await this.$http.get('/api/news/Get_newsreceiveorg', {
        params: {
          nNid: row.nNewId
        }
      })
      console.log(res);
      this.checkhuixian = res
      this.Allorganizations.forEach(row => {
        if (this.checkhuixian.indexOf(row.nOid) > 0) {
          console.log(row);
          this.$refs.multipleTable.toggleRowSelection(row, true);
        }
      })
      //   this.newsname = Cookies.get('username')
      // this.nUids = Cookies.get('nUid')
      // this.nOids = Cookies.get('nOid')
    },
       // 编辑时获取对应审核人员
    async getnUid () {
      console.log()
      const { data: res } = await this.$http.get('/api/user/Get_AlluserBynOid', {
        params: {
          innOid: this.formLabelAlign.region4
        }
      })
      console.log(res);
      this.newsAlluserBynOid = res
    },
      // 编辑时获取对应编写人员
    async getcnUid () {
      console.log()
      const { data: res } = await this.$http.get('/api/user/Get_AlluserBynOid', {
        params: {
          innOid: this.formLabelAlign.region6
        }
      })
      console.log(res);
      this.newsAlluserBynOid = res
    },
    topSort (a, b) {
      return Number(b.nTop) - Number(a.nTop);
    },
    fanhuiss () {
      this.addshow = false
      this.updateshow = false
      this.showneirong = true
      this.showxinzeng = false
      this.showtou = true
    },
    handleChange (file, fileList) {
      this.fileList = fileList.slice(-3);
    },
    handleSelectionChange (val) {
      this.multipleSelection = val;
    },
    // 上传照片
    handleRemove (file, fileList) {
      console.log(file, fileList);
    },
    handlePictureCardPreview (file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    // 人员id
    nuidnews (ids) {
      this.ids = ids
    },
    handleyes (file, fileList) {
      this.formLabelAlign.fujianname = fileList.name
      console.log(fileList.name);
    },
    handleRemove (file, fileList) {
      console.log(file, fileList);
    },
    handlePreview (file) {
      console.log(file);
    },
    handleExceed (files, fileList) {
      this.$message.warning(`当前限制选择 3 个文件，本次选择了 ${files.length} 个文件，共选择了 ${files.length + fileList.length} 个文件`);
    },
    beforeRemove (file, fileList) {
      return this.$confirm(`确定移除 ${file.name}？`);
    }
  }
};
</script>
<style scoped lang="css" src="./assets/index.css" />
